﻿Public Class FormJLJC
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim objJlMst As New clsJlMst
    Dim objJpMst As New clsJpMst
    Dim objJLJC As New clsJLJC
    Dim update_status As String = "INSERT_TYPE"
    Dim en As entityJLJC
    Dim _sys_id As String

    Public Property Sys_id As String
        Get
            Return _sys_id
        End Get
        Set(value As String)
            _sys_id = value
        End Set
    End Property

    Private Sub FormJLJC_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = GetIniFile("JS", "JS1", "", g_jsInitFileName)
        txtDate.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True
        txtDate.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True
        initForm()
        If _sys_id <> "" Then
            update_status = "UPDATE_TYPE"
            setContentBySysid()
        Else
            update_status = "INSERT_TYPE"
        End If
    End Sub

    Private Sub initForm()
        Dim reasons As String = GetIniFile("JLJC", "REASON", "", g_jsInitFileName)
        Dim reasonList As String() = reasons.Split("，")
        cmbReason.Items.Clear()
        cmbReason.Items.Add(String.Empty)
        For index = 0 To reasonList.Count() - 1
            cmbReason.Items.Add(reasonList(index))
        Next
        If cmbReason.Items.Count > 0 Then
            cmbReason.SelectedIndex = 0
        End If
        Dim TDate As String = Now.ToString()
        txtDate.Text = TDate
        Dim dtJp As DataTable = objJpMst.getAllList()
        cmb_jp_type.DisplayMember = "jp_name"
        cmb_jp_type.ValueMember = "material_code"
        cmb_jp_type.DataSource = dtJp
        If dtJp.Rows.Count > 0 Then
            cmb_jp_type.SelectedIndex = 0
        End If
        Dim dtJl As DataTable = objJlMst.getList()
        cmb_jl_type.DisplayMember = "mst_value"
        cmb_jl_type.ValueMember = "mst_value"
        cmb_jl_type.DataSource = dtJl
        If dtJl.Rows.Count > 0 Then
            cmb_jl_type.SelectedIndex = 0
        End If
        txt_LGWD.Value = 0
        txt_JCWD.Value = 0
        txt_SH1WD.Value = 0
        txt_SH2WD.Value = 0
        txt_SMWD.Value = 0
        txt_XMWD.Value = 0
        txt_SGWD.Value = 0
        txt_XGWD.Value = 0
        'txt_count.Value = 0
        rbOK_hlj.Checked = True
        rbOK_jp.Checked = True
        txt_YYCZ.Value = 0 '压延辊距(mm)
        txt_YYHWD.Value = 0 '压延后胶片温度(℃)
        'txt_LQSWD.Value = 0
        txt_LQHWD.Value = 0 '冷却后胶片温度(℃)
        txt_note.Text = String.Empty
    End Sub

    Private Sub setContentBySysid()
        Dim dt As DataTable = objJLJC.selectBySysid(_sys_id)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            txtDate.Text = row("prod_date")
            cmb_jl_type.Text = row("jl_type")
            cmb_jp_type.SelectedValue = row("jp_type")
            'txt_count.Text = row("count")
            txt_LGWD.Text = row("lg_temp")
            txt_JCWD.Text = row("jc_temp")
            txt_SH1WD.Text = row("sh1_temp")
            txt_SH2WD.Text = row("sh2_temp")
            txt_SMWD.Text = row("sm_temp")
            txt_XMWD.Text = row("xm_temp")
            txt_XGWD.Text = row("xg_temp")
            txt_SGWD.Text = row("sg_temp")
            txt_YYCZ.Text = row("yyjczcgj")
            txt_YYQD.Text = row("yyjqdcgj")
            txt_YYHWD.Text = row("yyjp_temp")
            'txt_LQSWD.Text = row("lqs_temp")
            txt_LQHWD.Text = row("lqjp_temp")
            If row("appearance_hlj") = 1 Then
                rbOK_hlj.Checked = True
            Else
                rbNG_hlj.Checked = False
            End If

            If row("appearance_jp") = 1 Then
                rbOK_jp.Checked = True
            Else
                rbNG_jp.Checked = False
            End If

            txt_note.Text = row("note")
        End If
    End Sub

    Private Sub txt_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_LGWD.MouseDown, txt_JCWD.MouseDown, txt_SH1WD.MouseDown, txt_SH2WD.MouseDown,
       txt_SMWD.MouseDown, txt_XMWD.MouseDown, txt_SGWD.MouseDown, txt_XGWD.MouseDown, txt_YYCZ.MouseDown, txt_YYQD.MouseDown, txt_YYHWD.MouseDown, txt_LQHWD.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub setEntity()
        en = New entityJLJC
        With en
            .sys_id = _sys_id
            .factory_id = "TS"
            .prod_date = txtDate.Text
            .jl_type = cmb_jl_type.Text
            .jp_type = cmb_jp_type.SelectedValue
            .lg_temp = txt_LGWD.Text
            .jc_temp = txt_JCWD.Text
            .sh1_temp = txt_SH1WD.Text
            .sh2_temp = txt_SH2WD.Text
            .sm_temp = txt_SMWD.Text
            .xm_temp = txt_XMWD.Text
            .sg_temp = txt_XGWD.Text
            .xg_temp = txt_XGWD.Text
            '.count = txt_count.Text
            .yyjczcgj = txt_YYCZ.Text
            .yyjqdcgj = txt_YYQD.Text
            .yyjp_temp = txt_YYHWD.Text
            '.lqs_temp = txt_LQSWD.Text
            .lqjp_temp = txt_LQHWD.Text
            .appearance_hlj = IIf(rbOK_hlj.Checked = True, "1", "0")
            .appearance_jp = IIf(rbOK_jp.Checked = True, "1", "0")
            .appearance_jp_reason = cmbReason.Text.Trim()
            .appearance_jp_reason_details = txtReasonDetails.Text.Trim()
            .note = txt_note.Text
            .oper = usr
        End With

    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(txtDate.Text.Trim()) Then
            MsgBox("请选择生产日期", vbYes, "提示")
            Exit Sub
        End If
        'If txt_count.Value <= 0 Then
        '    MsgBox("数量需大于0", vbYes, "提示")
        '    Exit Sub
        'End If
        If rbNG_jp.Checked Then
            If String.IsNullOrEmpty(cmbReason.Text.Trim()) Then
                MsgBox("请选择胶片外观不合格原因", vbYes, "提示")
                Exit Sub
            Else
                If cmbReason.Text.Trim().Equals("其他") Then
                    If String.IsNullOrEmpty(txtReasonDetails.Text.Trim()) Then
                        MsgBox("请填写胶片外观不合格其他具体原因", vbYes, "提示")
                        Exit Sub
                    End If
                End If
            End If
        End If
        setEntity()
        If update_status = "INSERT_TYPE" Then
            If objJLJC.insert(en) <> -2 Then
                MsgBox("保存成功")
                initForm()
            Else
                MsgBox("保存失败")
            End If
        End If
        If update_status = "UPDATE_TYPE" Then
            If objJLJC.update(en) <> -2 Then
                MsgBox("保存成功")
                CType(Owner, FormJLJCRecord).setDgvData()
                Close()
            Else
                MsgBox("保存失败")
            End If
        End If
    End Sub

    Private Sub rbNG_jp_CheckedChanged(sender As Object, e As EventArgs) Handles rbNG_jp.CheckedChanged
        If rbNG_jp.Checked Then
            cmbReason.Enabled = True
            txtReasonDetails.Enabled = True
        End If
    End Sub

    Private Sub rbOK_jp_CheckedChanged(sender As Object, e As EventArgs) Handles rbOK_jp.CheckedChanged
        If rbOK_jp.Checked Then
            If cmbReason.Items.Count > 0 Then
                cmbReason.SelectedIndex = 0
                cmbReason.Enabled = False
            End If
            txtReasonDetails.Text = String.Empty
            txtReasonDetails.Enabled = False
        End If
    End Sub

End Class

Public Class entityJLJC
    Public sys_id As String
    Public factory_id As String
    Public prod_date As String '生产日期
    Public jl_type As String
    Public jp_type As String
    Public lg_temp As String '螺杆温度
    Public jc_temp As String '挤出温度
    Public sh1_temp As String '塑化Ⅰ温度
    Public sh2_temp As String '塑化Ⅱ温度
    Public sm_temp As String '上模温度
    Public xm_temp As String '下模温度
    Public sg_temp As String '上辊温度
    Public xg_temp As String '下辊温度
    'Public count As String
    Public yyjczcgj As String '压延机操作侧辊距
    Public yyjqdcgj As String '压延机驱动侧辊距
    Public yyjp_temp As String '压延后温度
    Public lqjp_temp As String '冷却后温度
    Public appearance_hlj As String '混炼胶外观OK/NG
    Public appearance_jp As String '胶片外观OK/NG
    Public appearance_jp_reason As String
    Public appearance_jp_reason_details As String
    'Public lqs_temp As String
    Public note As String
    Public oper As String
End Class